home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / progs / demo / X11 / animation / r_curve.hs < prev    next >
Encoding:
Text File  |  1994-09-27  |  2.0 KB  |  61 lines  |  [TEXT/YHS2]

  1. {-**************************************************************
  2.   MODULE R_CURVE
  3.  
  4.     This module produces sequences of numbers to be used by
  5.   Behaviours. The sequences used for moving or scaling can
  6.   be produced here, in either linear sequences or accelerating
  7.   and decelerating sequences.
  8.     The acceleration functions produce floats, so the vftov function
  9.   would have to be used to convert floating point vectors to integer
  10.   vectors.
  11.  
  12. ***************************************************************-}
  13.  
  14. module R_Curve(lnr,hold, acc, dec, accdec, decacc) where
  15.  
  16. import R_Ptypes
  17. import R_Constants
  18. import R_Utility
  19. import R_Picture
  20. import R_Behaviour
  21.  
  22.   -- lnr takes the start, finish and the number of intervals and
  23.   -- produces a linear list of ints going from the start to finish.
  24. lnr :: Int -> Int -> Int ->[Int]
  25. lnr start fin n = take n [start,(start+step)..]
  26.             where step = ((fin-start)`div`(n-1))
  27.  
  28.   -- hold produces an infinite number of ints starting at v, modified
  29.   -- by step every time.
  30. hold :: Int -> Int -> [Int]  
  31. hold v step  = [v,v+step..]
  32.  
  33.   -- acc accelerates from 0 to the max in n steps.
  34. acc :: Int -> Int -> Int -> [Int]
  35. acc min max n = min:acc' min (max-min) n 1 
  36.  
  37. acc' ::  Int -> Int -> Int -> Int -> [Int]
  38. acc' min max n c | (c>n) = []
  39. acc' min max n c         = (min + (((max*c*c) `div` (n*n)))) 
  40.                            : (acc' min max n (c+1)) 
  41.  
  42.  
  43.   -- dec decelerates from the max to 0 in n steps.
  44. dec :: Int -> Int -> Int -> [Int]
  45. dec min max n = reverse (acc min max n)
  46.   
  47.   -- accdec accelerates from start up to max and back to fin, in an steps
  48.   -- accelerating and dn steps decelerating
  49. accdec :: Int -> Int -> Int -> Int -> Int -> [Int]
  50. accdec start max fin an dn = (acc start max an)++(tail (dec fin max dn))
  51.  
  52.   -- decacc decelerates from start to min in dn steps and then accelerates
  53.   -- back up to fin in an more steps
  54. decacc :: Int -> Int -> Int -> Int -> Int -> [Int]
  55. decacc start min fin dn an = (dec min start dn)++(tail (acc min fin an))
  56.  
  57.  
  58.  
  59.  
  60.  
  61.